package Annotate;

import org.junit.Test;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Arrays;

public class AnnotationTest2 {//看到注解的属性，
    @Test
    public void parseClass(){
        Class c= Demo.class;
        //1.解析类上的注解
        if(c.isAnnotationPresent(MyTest3.class)){
            Annotation myTest33=c.getDeclaredAnnotation(MyTest3.class);//多态，继承Annotatino
            MyTest3 myTest3=(MyTest3) c.getDeclaredAnnotation(MyTest3.class);//最好还是强转
            System.out.println(myTest3.value());
            System.out.println(myTest3.aaa());
            System.out.println(Arrays.toString(myTest3.bbb()));
        }
    }
    @Test
    public void parseMethod() throws Exception {
        Class c= Demo.class;
        Method method =c.getDeclaredMethod("test1");//找到一个类里面的一个方法的对象
        if(c.isAnnotationPresent(MyTest3.class)){
            MyTest3 myTest3= method.getDeclaredAnnotation(MyTest3.class);//最好还是强转
            System.out.println(myTest3.value());
            System.out.println(myTest3.aaa());
            System.out.println(Arrays.toString(myTest3.bbb()));
        }
    }
}
